<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>编辑专用</title>
    <link href="/image/favicon.ico" rel="shortcut icon" />
    <script src="http://how2j.cn/study/js/jquery/2.0.0/jquery.min.js"></script>
    <link href="http://how2j.cn/study/css/bootstrap/3.3.6/bootstrap.min.css" rel="stylesheet">
    <script src="http://how2j.cn/study/js/bootstrap/3.3.6/bootstrap.min.js"></script>
    <script type="text/javascript">
        /*<![CDATA[*/
        $(document).ready(function(){
            $(".tag").bind("input propertychange","textarea",function(){
                var tag = $(this).val();
                var alist = $(this).parent().next().children();
                $.each(alist,function () {
                    $(this).attr("href",$(this).next().val() +tag);
                })
            });
            $(".change").click(function () {
               alert("操作成功");
            });

            $(".thtitle").click(function() {
                var s = window.getSelection().toString();
                if(s!="") {
                    var tag = $(this).next().next().next().children();
                    tag.val(tag.val() + "," + s);
                    var alist = tag.parent().next().children();
                    $.each(alist, function () {
                        $(this).attr("href", $(this).next().val() + tag.val());
                    })
                }
            });
        });
        /*]]>*/
    </script>
</head>
<body>
    <a href="/"><img src="/image/logo.png"/></a>
    <form action="/edit/getnews">
        <input class="btn btn-info" type="submit" value="爬取新闻并审核">
    </form>
    <br/>
    <form action="/edit/switch">
        <input class="btn btn-info" th:if="${session.switch==null}" type="submit" value="切换为已发布新闻">
        <input class="btn btn-info" th:if="${session.switch!=null}" type="submit" value="切换为待审核新闻">
    </form>
    <hr/>
    <p th:if="${getCount!=null}" th:text="'爬取了'+${getCount}+'条新新闻'"></p>
    <p th:if="${newsCount!=null}" th:text="'有'+${newsCount}+'条新闻可编辑'"></p>
    <nav>
        <ul class="pagination">
            <li><a th:href="@{/edit?pageNumber=0}">首页</a></li>
            <li th:if="${isFirstPage}" class="disabled"><span>上一页</span></li>
            <li th:if="${not isFirstPage}"><a th:href="@{'/edit?pageNumber='+${pageNum-1}}">上一页</a></li>
            <li th:if="${isLastPage}" class="disabled"><span>下一页</span></li>
            <li th:if="${not isLastPage}"><a th:href="@{'/edit?pageNumber='+${pageNum+1}}">下一页</a></li>
            <li><a th:href="@{'/edit?pageNumber='+${totalPages}}">尾页</a></li>
        </ul>
    </nav>
    <table style="table-layout:fixed" class="table table-condensed table-bordered table-hover table-striped">
        <tr>
            <th width="20%">标题(划词快速添加关键字)</th>
            <th width="6%">作者</th>
            <th>内容</th>
            <th width="20%">TAG(用英文“,”间隔多类型)</th>
            <th width="14%">操作</th>
        </tr>
        <tr th:each="news:${editNews}">
            <td class="thtitle" th:text="${news.title}"></td>
            <td th:text="${news.author}"></td>
            <td style="overflow:hidden;white-space:nowrap;text-overflow:ellipsis;" th:text="${news.context}"></td>
            <td><textarea class="tag" style="resize: none;width:100%;" th:text="${news.type}"></textarea></td>
            <td th:if="${session.switch==null}" valign="top">
                <a th:href="@{'/edit/'+${news.id}+'?type=明星,'+${news.type}}">明星</a>
                <input type="hidden" th:attr="value='/edit/'+${news.id}+'?type=明星,'">
                <a th:href="@{'/edit/'+${news.id}+'?type=时尚,'+${news.type}}">时尚</a>
                <input type="hidden" th:attr="value='/edit/'+${news.id}+'?type=时尚,'">
                <a th:href="@{'/edit/'+${news.id}+'?type=影视,'+${news.type}}">影视</a>
                <input type="hidden" th:attr="value='/edit/'+${news.id}+'?type=影视,'">
                <a th:href="@{'/edit/'+${news.id}+'?type=宠物,'+${news.type}}">宠物</a>
                <input type="hidden" th:attr="value='/edit/'+${news.id}+'?type=宠物,'">
                <a th:href="@{'/edit/'+${news.id}+'?type=生活,'+${news.type}}">生活</a>
                <input type="hidden" th:attr="value='/edit/'+${news.id}+'?type=生活,'">
                <a th:href="@{'/edit/'+${news.id}+'?type=删除'}"><p class="text-danger">删除</p></a>
                <input type="hidden" th:attr="value='/edit/'+${news.id}+'?type=删除,'">
            </td>
            <td th:if="${session.switch!=null}" valign="top">
                <a class="change" th:href="@{'/edit/'+${news.id}+'?type='+${news.type}}">更改</a>
                <input type="hidden" th:attr="value='/edit/'+${news.id}+'?type='">
                <a th:href="@{'/edit/'+${news.id}+'?type=删除'}"><p class="text-danger">删除</p></a>
                <input type="hidden" th:attr="value='/edit/'+${news.id}+'?type=删除,'">
            </td>
        </tr>
    </table>
</body>
</html>